﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Maticsoft.Common;

namespace Golf.WebUI.AdminShow.CustomerManagement
{
    public partial class Golf_AddressUpdate : Golf.WebUI.App_code.ValidateLogin
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int Id = (Convert.ToInt32(Request.Params["id"]));
                    ShowInfo(Id);
                }
            }
        }

        private void ShowInfo(int Id)
        {
            Golf.BLL.Golf_Address bll = new Golf.BLL.Golf_Address();
            Golf.Model.Golf_Address model = bll.GetModel(Id);
            this.lblId.Text = model.Id.ToString();
            this.txtUserId.Text = model.UserId.ToString();
            this.txtFristName.Text = model.FristName;
            this.txtLastName.Text = model.LastName;
            this.txtConsigneeFrist.Text = model.ConsigneeFrist;
            this.txtConsigneeLast.Text = model.ConsigneeLast;
            this.txtMobile.Text = model.Mobile;
            this.txtTel.Text = model.Tel;
            this.txtFax.Text = model.Fax;
            this.txtPostCode.Text = model.PostCode;
            this.txtAddress.Text = model.Address;
            this.txtEmail.Text = model.Email;
            this.txtFitDeliveryTime.Text = model.FitDeliveryTime.ToString();
            this.txtProvince.Text = model.Province;
            this.txtCity.Text = model.City;
            this.txtBorough.Text = model.Borough;
            this.txtCreateTime.Text = model.CreateTime.ToString();
            this.chkIsShow.Checked = model.IsShow;

        }

        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            if (!PageValidate.IsNumber(txtUserId.Text))
            {
                strErr += "会员id格式错误！\\n";
            }
            if (this.txtFristName.Text.Trim().Length == 0)
            {
                strErr += "姓不能为空！\\n";
            }
            if (this.txtLastName.Text.Trim().Length == 0)
            {
                strErr += "名不能为空！\\n";
            }
            if (this.txtConsigneeFrist.Text.Trim().Length == 0)
            {
                strErr += "收货人(姓)不能为空！\\n";
            }
            if (this.txtConsigneeLast.Text.Trim().Length == 0)
            {
                strErr += "收货人(名)不能为空！\\n";
            }
            if (this.txtMobile.Text.Trim().Length == 0)
            {
                strErr += "手机不能为空！\\n";
            }
            if (this.txtTel.Text.Trim().Length == 0)
            {
                strErr += "电话不能为空！\\n";
            }
            if (this.txtFax.Text.Trim().Length == 0)
            {
                strErr += "传真不能为空！\\n";
            }
            if (this.txtPostCode.Text.Trim().Length == 0)
            {
                strErr += "邮编不能为空！\\n";
            }
            if (this.txtAddress.Text.Trim().Length == 0)
            {
                strErr += "地址不能为空！\\n";
            }
            if (this.txtEmail.Text.Trim().Length == 0)
            {
                strErr += "邮件不能为空！\\n";
            }
            if (!PageValidate.IsNumber(txtFitDeliveryTime.Text))
            {
                strErr += "适合收货时间格式错误！\\n";
            }
            if (this.txtProvince.Text.Trim().Length == 0)
            {
                strErr += "省不能为空！\\n";
            }
            if (this.txtCity.Text.Trim().Length == 0)
            {
                strErr += "市不能为空！\\n";
            }
            if (this.txtBorough.Text.Trim().Length == 0)
            {
                strErr += "区不能为空！\\n";
            }
            if (!PageValidate.IsDateTime(txtCreateTime.Text))
            {
                strErr += "创建时间格式错误！\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int Id = int.Parse(this.lblId.Text);
            int UserId = int.Parse(this.txtUserId.Text);
            string FristName = this.txtFristName.Text;
            string LastName = this.txtLastName.Text;
            string ConsigneeFrist = this.txtConsigneeFrist.Text;
            string ConsigneeLast = this.txtConsigneeLast.Text;
            string Mobile = this.txtMobile.Text;
            string Tel = this.txtTel.Text;
            string Fax = this.txtFax.Text;
            string PostCode = this.txtPostCode.Text;
            string Address = this.txtAddress.Text;
            string Email = this.txtEmail.Text;
            int FitDeliveryTime = int.Parse(this.txtFitDeliveryTime.Text);
            string Province = this.txtProvince.Text;
            string City = this.txtCity.Text;
            string Borough = this.txtBorough.Text;
            DateTime CreateTime = DateTime.Parse(this.txtCreateTime.Text);
            bool IsShow = this.chkIsShow.Checked;


            Golf.Model.Golf_Address model = new Golf.Model.Golf_Address();
            model.Id = Id;
            model.UserId = UserId;
            model.FristName = FristName;
            model.LastName = LastName;
            model.ConsigneeFrist = ConsigneeFrist;
            model.ConsigneeLast = ConsigneeLast;
            model.Mobile = Mobile;
            model.Tel = Tel;
            model.Fax = Fax;
            model.PostCode = PostCode;
            model.Address = Address;
            model.Email = Email;
            model.FitDeliveryTime = FitDeliveryTime;
            model.Province = Province;
            model.City = City;
            model.Borough = Borough;
            model.CreateTime = CreateTime;
            model.IsShow = IsShow;

            Golf.BLL.Golf_Address bll = new Golf.BLL.Golf_Address();
            bll.Update(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "list.aspx");

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }

}